#include "PropertyList.h"
Property* PropertyList::findProperty(char* a_name)
{
	for(int i = 0; i < m_cards.size(); i++)
		if(strncmp(m_cards[i].getName(), a_name, 20) == 0)
			return &m_cards[i];

	return 0;
}
bool PropertyList::loadFromFile(char* a_filename)
{
	Property* newProp;
	ifstream infile(a_filename);
	char token;
	char dummy[256];
	
	// Variables we want to read
	int rent[RENT_SIZE];
	int mortgage;
	int housePrice;		
	int color;		
	char* name;

	if(!infile.is_open())
	{
		printf("File could not be opened!\n");
		return false;
	}

	while(!infile.eof())
	{
		// Read one character
		token = infile.peek();
		
		// Ignore comments and empty lines
		if(token == '#' || token == '\n' || token == '\r')
		{ 
			infile.getline(dummy, 255, '\n');
		}
		else // Found a good token!
		{
			// Clean out our temporary variables.
			name = new char[256];
			color = 0;
			housePrice = mortgage = 0;
			for(int i = 0; i < RENT_SIZE; i++)
				rent[i] = 0;

			// Load the Name
			infile.getline(name, 255, '\n');
				
			// Load the Color
			infile >> color;
			
			// Increment the number of properties for this color
			m_colors[color]++;

			// Load the Rent
			for(int i = 0; i < RENT_SIZE; i++)
				infile >> rent[i];

			// Load the Mortgage
			infile >> mortgage;

			// Load the House price
			infile >> housePrice;

			// Create the card and push it back						
			newProp = new Property(name, rent, mortgage, housePrice, color);

			m_cards.push_back(*newProp);
		}
	}

	return true;
}